/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mes.quality.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.mes.quality.entity.AnalysisAssemblyOffline;
import org.springblade.modules.mes.quality.service.IAnalysisAssemblyOfflineService;
import org.springblade.modules.mes.quality.vo.AnalysisAssemblyOfflineVO;
import org.springblade.modules.mes.quality.vo.AssemblyNoVo;
import org.springblade.modules.mes.quality.wrapper.AnalysisAssemblyOfflineWrapper;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 质量分析-总成下线数据 控制器
 *
 * @author liuchao
 * @since 2023-02-20
 */
@RestController
@AllArgsConstructor
@RequestMapping("/analysisAssemblyOffline")
@Api(value = "质量分析-总成下线数据", tags = "质量分析-总成下线数据接口")
public class AnalysisAssemblyOfflineController extends BladeController {

    private final IAnalysisAssemblyOfflineService analysisAssemblyOfflineService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    //@ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入analysisAssemblyOffline")
    public R<AnalysisAssemblyOfflineVO> detail(AnalysisAssemblyOffline analysisAssemblyOffline) {
        AnalysisAssemblyOffline detail = analysisAssemblyOfflineService.getOne(Condition.getQueryWrapper(analysisAssemblyOffline));
        return R.data(AnalysisAssemblyOfflineWrapper.build().entityVO(detail));
    }

    /**
     * 不分页 质量分析-总成下线数据
     */
    @GetMapping("/list")
    //@ApiOperationSupport(order = 2)
    @ApiOperation(value = "不分页 质量分析-总成下线数据", notes = "传入analysisAssemblyOffline")
    public R<List<AnalysisAssemblyOffline>> list(AnalysisAssemblyOffline analysisAssemblyOffline) {
        List<AnalysisAssemblyOffline> analysisAssemblyOfflineList = analysisAssemblyOfflineService.list(new LambdaQueryWrapper<AnalysisAssemblyOffline>().eq(AnalysisAssemblyOffline::getAssemblyNewBarcode, analysisAssemblyOffline.getAssemblyNewBarcode()));
        return R.data(analysisAssemblyOfflineList);
    }


    /**
     * 自定义分页 质量分析-总成下线数据
     */
    @GetMapping("/page")
    //@ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入analysisAssemblyOffline")
    public R<IPage<AnalysisAssemblyOfflineVO>> page(AnalysisAssemblyOfflineVO analysisAssemblyOffline, Query query) {
        IPage<AnalysisAssemblyOfflineVO> pages = analysisAssemblyOfflineService.selectAnalysisAssemblyOfflinePage(Condition.getPage(query), analysisAssemblyOffline);
        return R.data(pages);
    }

    /**
     * 删除 质量分析-总成下线数据
     */
    @PostMapping("/remove")
    //@ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(analysisAssemblyOfflineService.deleteLogic(Func.toLongList(ids)));
    }

    @GetMapping("/updateChassisNo")
    //@ApiOperationSupport(order = 8)
    @ApiOperation(value = "更新底盘号-fis使用")
    public void updateChassisNo(@RequestParam String assemblyNo, @RequestParam String assemblyFlowNo, @RequestParam String chassisNo){
        analysisAssemblyOfflineService.updateChassisNo(assemblyNo,assemblyFlowNo,chassisNo);
    }
//    @GetMapping("/million")
//    //@ApiOperationSupport(order = 8)
//    @ApiOperation(value = "插入100万条数据")
//    public void million() {
//        analysisAssemblyOfflineService.million();
//    }

    /**
     * 获取质量总成号总成名称列表
     */
    @PostMapping("/getAssemblyNoPage")
    //@ApiOperationSupport(order = 9)
    @ApiOperation(value = "获取质量总成号总成名称列表", notes = "传入assemblyNoVo")
    public R<IPage<AssemblyNoVo>> getAssemblyNoPage(@RequestBody AssemblyNoVo assemblyNoVo) {
        IPage<AssemblyNoVo> pages = analysisAssemblyOfflineService.getAssemblyNoPage(Condition.getPage(assemblyNoVo.getQuery()), assemblyNoVo);
        return R.data(pages);
    }

    /**
     * 获取质量总成号下流水号列表
     */
    @PostMapping("/getAssemblyBarcodePage")
    //@ApiOperationSupport(order = 10)
    @ApiOperation(value = "获取质量总成号下流水号列表", notes = "传入assemblyNoVo")
    public R<IPage<AssemblyNoVo>> getAssemblyBarcodePage(@RequestBody AssemblyNoVo assemblyNoVo) {
        IPage<AssemblyNoVo> pages = analysisAssemblyOfflineService.getAssemblyBarcodePage(Condition.getPage(assemblyNoVo.getQuery()), assemblyNoVo);
        return R.data(pages);
    }

    /**
     * 根据总成流水获取质量总成下线数据
     */
    @PostMapping("/getAssemblyNoByList")
    //@ApiOperationSupport(order = 10)
    @ApiOperation(value = "根据总成流水获取质量总成下线数据", notes = "传入assList")
    public R<List<AssemblyNoVo>> getAssemblyNoByList(@RequestBody List<String> assList) {
        List<AssemblyNoVo> assemblyNoVoList = analysisAssemblyOfflineService.getAssemblyNoByList(assList);
        return R.data(assemblyNoVoList);
    }
}
